package yaner.hotel.manager.resource.mapper.impl;

import org.springframework.stereotype.Component;
import yaner.hotel.manager.common.dto.room.RoomAddDto;
import yaner.hotel.manager.common.dto.room.RoomUpdateDto;
import yaner.hotel.manager.common.vo.RoomVo;
import yaner.hotel.manager.resource.entity.Room;
import yaner.hotel.manager.resource.mapper.IRoomMapper;

import java.util.Date;
import java.util.Objects;

@Component
public class RoomMapperImpl implements IRoomMapper {
    @Override
    public RoomVo toVo(Room room) {
        Objects.requireNonNull(room, "RoomMapperImpl toVo room is null");
        return RoomVo.builder()
                .roomId(room.getRoomId())
                .roomTypeId(room.getRoomTypeId())
                .number(room.getNumber())
                .roomStatus(room.getRoomStatus())
                .length(room.getLength())
                .height(room.getHeight())
                .width(room.getWidth())
                .infrastructureId(room.getInfrastructureId())
                .build();
    }

    @Override
    public Room toAddEntity(RoomAddDto roomAddDto) {
        Objects.requireNonNull(roomAddDto, "RoomMapperImpl toAddEntity roomAddDto is null");
        return Room.builder()
                .roomTypeId(roomAddDto.getRoomTypeId())
                .number(roomAddDto.getNumber())
                .roomStatus(roomAddDto.getRoomStatus())
                .length(roomAddDto.getLength())
                .height(roomAddDto.getHeight())
                .width(roomAddDto.getWidth())
                .infrastructureId(roomAddDto.getInfrastructureId())
                .createTime(new Date())
                .updateTime(new Date())
                .build();
    }

    @Override
    public Room toUpdateEntity(RoomUpdateDto roomUpdateDto) {
        Objects.requireNonNull(roomUpdateDto, "RoomMapperImpl toUpdateEntity roomUpdateDto is null");
        return Room.builder()
                .roomTypeId(roomUpdateDto.getRoomTypeId())
                .number(roomUpdateDto.getNumber())
                .roomStatus(roomUpdateDto.getRoomStatus())
                .length(roomUpdateDto.getLength())
                .height(roomUpdateDto.getHeight())
                .width(roomUpdateDto.getWidth())
                .infrastructureId(roomUpdateDto.getInfrastructureId())
                .updateTime(new Date())
                .build();
    }
}
